package com.lavender.transaction.controller;

import com.lavender.transaction.entity.Account;
import com.lavender.transaction.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/account")
@RestController
public class AccountController {

    @Autowired
    private AccountService accountService;

    // http://localhost:8081/account/test
    @GetMapping("test")
    public String test() {
        accountService.deleteAll();
        Account account = new Account();
        account.setUserId("admin");
        account.setMoney(100);
        accountService.insert(account);
        Account account1 = accountService.selectByUserId(account);
        System.out.println("order1:" + account1);
        account1.setMoney(200);
        accountService.updateByUserId(account);
        Account account2 = accountService.selectByUserId(account);
        System.out.println("order2:" + account2);
        accountService.deleteByUserId(account);
        Account account3 = accountService.selectByUserId(account);
        System.out.println("order3:" + account3);
        return "ok";
    }

}
